/*
*  Copyright 2019-2025 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package me.zhengjie.modules.transfer.service.impl;

import me.zhengjie.modules.transfer.domain.TransferIc69;
import me.zhengjie.utils.FileUtil;
import lombok.RequiredArgsConstructor;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import me.zhengjie.modules.transfer.service.TransferIc69Service;
import me.zhengjie.modules.transfer.domain.dto.TransferIc69QueryCriteria;
import me.zhengjie.modules.transfer.mapper.TransferIc69Mapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import me.zhengjie.utils.PageUtil;
import java.util.List;
import java.util.Map;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import me.zhengjie.utils.PageResult;

/**
* @description 服务实现
* @author lzw
* @date 2025-05-29
**/
@Service
@RequiredArgsConstructor
public class TransferIc69ServiceImpl extends ServiceImpl<TransferIc69Mapper, TransferIc69> implements TransferIc69Service {

    private final TransferIc69Mapper transferIc69Mapper;

    @Override
    public PageResult<TransferIc69> queryAll(TransferIc69QueryCriteria criteria, Page<Object> page){
        return PageUtil.toPage(transferIc69Mapper.findAll(criteria, page));
    }

    @Override
    public List<TransferIc69> queryAll(TransferIc69QueryCriteria criteria){
        return transferIc69Mapper.findAll(criteria);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void create(TransferIc69 resources) {
        transferIc69Mapper.insert(resources);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void update(TransferIc69 resources) {
        TransferIc69 transferIc69 = getById(resources.getAaz341());
        transferIc69.copy(resources);
        transferIc69Mapper.updateById(transferIc69);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteAll(List<String> ids) {
        transferIc69Mapper.deleteBatchIds(ids);
    }

    @Override
    public void download(List<TransferIc69> all, HttpServletResponse response) throws IOException {
        List<Map<String, Object>> list = new ArrayList<>();
        for (TransferIc69 transferIc69 : all) {
            Map<String,Object> map = new LinkedHashMap<>();
            map.put("人员参保关系ID", transferIc69.getAaz159());
            map.put("转出地行政区划代码", transferIc69.getAab299());
            map.put("转入地行政区划代码", transferIc69.getAab301());
            map.put("联系函编号", transferIc69.getAae270());
            map.put("转入险种类型", transferIc69.getAae140());
            map.put("转出险种类型", transferIc69.getAae241());
            map.put("人员编号", transferIc69.getAac001());
            map.put("转出地人员编号", transferIc69.getAac319());
            map.put("姓名", transferIc69.getAac003());
            map.put("性别", transferIc69.getAac004());
            map.put("公民身份号码", transferIc69.getAac002());
            map.put("新就业地职业（企业）年金管理机构全称", transferIc69.getAae009());
            map.put("新就业地职业（企业）年金管理机构地址", transferIc69.getAae006());
            map.put("新就业地职业（企业）年金管理机构邮政编码", transferIc69.getAae007());
            map.put("新就业地职业（企业）年金管理机构联系人", transferIc69.getAae004());
            map.put("新就业地职业（企业）年金管理机构联系电话", transferIc69.getAae005());
            map.put("新就业地社保机构职业年金开户全称", transferIc69.getAac077());
            map.put("新就业地社保机构职业年金银行", transferIc69.getAac155());
            map.put("新就业地社保机构职业年金账号", transferIc69.getAac078());
            map.put("新就业地单位企业年金开户全称", transferIc69.getAac072());
            map.put("新就业地单位企业年金银行", transferIc69.getAaf011());
            map.put("新就业地单位企业年金银行账号", transferIc69.getAac073());
            map.put("经办人电话(年金用）", transferIc69.getAae251());
            map.put("转移数据来源", transferIc69.getAac306());
            map.put("联网下载标志", transferIc69.getAae732());
            map.put("被确认标志", transferIc69.getAae733());
            map.put("联网发送标志", transferIc69.getAae731());
            map.put("上传方经办人", transferIc69.getAae736());
            map.put("上传方经办时间", transferIc69.getAae739());
            map.put("备注", transferIc69.getAae013());
            map.put("经办人", transferIc69.getAae011());
            map.put("经办时间", transferIc69.getAae036());
            map.put("经办机构", transferIc69.getAab359());
            map.put("业务日志ID", transferIc69.getAaz002());
            list.add(map);
        }
        FileUtil.downloadExcel(list, response);
    }
}
